package com.framework.spring.context.bfpp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

@Slf4j(topic = "e")
public class C implements BeanDefinitionRegistryPostProcessor {

	public C() {
		log.info("C construct");
	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		log.info("api C#BeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry");
		// 可以注入的原因是通过api注入 能优先执行 所有能生效
		AbstractBeanDefinition xBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(X.class).getBeanDefinition();
		registry.registerBeanDefinition("x", xBeanDefinition);
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		log.info("api C#BeanDefinitionRegistryPostProcessor.postProcessBeanFactory");
	}
}
